#!/usr/bin/env python
# -*- coding=utf-8 -*-


def split_seq(seq,step):
    """
    split a string or list by step
    Example:
    seq = split_seq('ABCCBAAACCAAaa',3)
    seq2 = split_seq(seq,3)
    print(seq2)
    """
    if not isinstance(step,int):
        try:
            step = int(step)
        except ValueError:
            raise Exception('step must an integer!')
    i = 0
    split_list = []
    while True:
        start = i*step
        end = (i+1)*step
        contig = seq[start:end]
        # print(contig)
        if contig:#对list取区间子串时不会报IndexError，只返回一个空列表，单独取值时会报IndexError
            split_list.append(contig)
        else:
            break
        i += 1
    return split_list


if __name__ == "__main__":
    seq = split_seq('ABCCBAAACCAAaa',3)
    seq2 = split_seq(seq,3)
    print(seq2)